package cn.santi.controller;

import cn.santi.domain.JSearch;
import cn.santi.emuns.R;
import cn.santi.service.JSearchService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private JSearchService js;

    //显示搜索记录
    @GetMapping("/showseeklist")
    public R showseeklist(int uid,int tid){
        QueryWrapper<JSearch> wrapper = new QueryWrapper<>();
        wrapper.eq("uid",uid).eq("tid",tid);
        return R.ok(js.list(wrapper));
    }
    //添加搜索记录
    @GetMapping("/addseek")
    public R addseek(JSearch jSearch){
        QueryWrapper<JSearch> wrapper = new QueryWrapper<>();
        wrapper.eq("tid",jSearch.getTid()).eq("uid",jSearch.getUid()).eq("data",jSearch.getData());
        JSearch one = js.getOne(wrapper);
        if (one ==null){
            js.save(jSearch);
            return R.ok("成功");
        }
        return R.fail("失败");
    }
    //删除搜索记录
    @GetMapping("/delseek")
    public R delseek(int uid ,int tid){
        QueryWrapper<JSearch> wrapper = new QueryWrapper<>();
        wrapper.eq("uid",uid).eq("tid",tid);
        return R.ok(js.remove(wrapper));
    }

}
